import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AnimatedChristmasTree extends JFrame {
    private int treeHeight = 100;
    private int treeWidth = 100;
    private int treeTopX = 200;
    private int treeTopY = 200;

    public AnimatedChristmasTree() {
        setTitle("Animated Christmas Tree");
        setSize(400, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);

        Timer timer = new Timer(100, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (treeHeight < 300) {
                    treeHeight += 10;
                    treeWidth += 10;
                    treeTopX -= 5;
                    treeTopY -= 5;
                    repaint();
                }
            }
        });
        timer.start();
    }

    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(new Color(139, 69, 19));
        g.fillRect(treeTopX, treeTopY + treeHeight, treeWidth, treeHeight); // 绘制树干
        int[] x = {treeTopX, treeTopX - treeWidth / 2, treeTopX + treeWidth / 2};
        int[] y = {treeTopY, treeTopY + treeHeight, treeTopY + treeHeight};
        g.setColor(Color.GREEN);
        g.fillPolygon(x, y, 3); // 绘制树叶
    }

    public static void main(String[] args) {
        new AnimatedChristmasTree();
    }
}
